Skip to content

[ty] Split equality from other comparison inference#26370

Open
charliermarsh wants to merge 3 commits into
mainfrom
charlie/split-equality-comparison-inference
Open

[ty] Split equality from other comparison inference#26370
charliermarsh wants to merge 3 commits into
mainfrom
charlie/split-equality-comparison-inference

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

#26337 routes definite == and != results through the shared equality evaluator before falling back to normal expression inference. When that evaluator returns ambiguous truthiness, however, we still run the full comparison dispatcher, repeating literal, tuple, and constraint-set work just to distinguish a builtin bool result from an arbitrary custom comparison return type.

This splits the top-level dispatch between equality and the other comparison operators. Equality evaluation now distinguishes definite truthiness, ambiguous builtin bool, and comparisons whose result type still needs to be inferred. Known builtin comparisons can stop after the shared evaluator, while custom comparisons continue through structural dispatch and the existing dunder fallback. The remaining literal dispatch uses a narrower non-equality operator enum, so it no longer duplicates the == and != cases.

To make the shared path complete, this also moves constraint-set equality and builtin tuple equality into the equality evaluator. Fixed-length tuples compare their elements using equality semantics even for an outer !=, while uncertain element results still fall back to expression inference so custom return types and bool-conversion diagnostics are preserved. Regression coverage verifies that equality and inequality over union arms retain each custom dunder return type.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 25, 2026
@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch from 11023c6 to 8c8c117 Compare June 25, 2026 16:26
@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.44%. The percentage of expected errors that received a diagnostic held steady at 90.21%. The number of fully passing files held steady at 95/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch 3 times, most recently from c072fb1 to 60d8110 Compare June 25, 2026 17:17
@charliermarsh charliermarsh marked this pull request as ready for review June 25, 2026 17:18
@charliermarsh charliermarsh requested a review from a team as a code owner June 25, 2026 17:18
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila June 25, 2026 17:18
@charliermarsh charliermarsh added the internal An internal refactor or improvement label Jun 25, 2026
@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch from 60d8110 to 8952102 Compare June 26, 2026 11:10
@charliermarsh charliermarsh requested review from AlexWaygood and removed request for dhruvmanila June 26, 2026 12:44
@charliermarsh charliermarsh requested a review from carljm July 6, 2026 14:52
@charliermarsh charliermarsh force-pushed the charlie/split-equality-comparison-inference branch from 8952102 to 08107c5 Compare July 6, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant